#include "../../mqserver/exchange.hpp"
#include <gtest/gtest.h>

MyRabbitMQ::ExchangeManager::ptr hosts;

class ExchangeTest : public testing::Environment
{
    public:
    
    //初始化
    virtual void SetUp() override
    {
        hosts = std::make_shared<MyRabbitMQ::ExchangeManager>("./data.db");
    }

    virtual void TearDown() override
    {
        //清理交换机测试
        hosts->clear();
        std::cout << "执行真正数据库清理操作" << std::endl;
    }
};
//声明交换机测试
TEST(ExchangeTest,insert_test)
{
    hosts->declareExchange("exchange-1",protoMQ::ExchangeType::direct,
    true,false,google::protobuf::Map<std::string,std::string>());
    
    hosts->declareExchange("exchange-2",protoMQ::ExchangeType::direct,
    true,false,google::protobuf::Map<std::string,std::string>());
    
    hosts->declareExchange("exchange-3",protoMQ::ExchangeType::direct,
    false,false,google::protobuf::Map<std::string,std::string>());
}

//删除交换机测试
TEST(ExchangeTest, delete_test)
{
    hosts->deleteExchange("exchange-2");
    hosts->deleteExchange("exchange-3");
}

//获取指定交换机测试
TEST(ExchangeTest,get_test)
{
    auto exp = hosts->getExchange("exchange-1");
    LOG(logLevel::DEBUG) << exp->m_name << std::endl;
    LOG(logLevel::DEBUG) << exp->m_type << std::endl;
    LOG(logLevel::DEBUG) << exp->m_isDurable << std::endl;
    LOG(logLevel::DEBUG) << exp->m_isAutoDelete << std::endl;
    LOG(logLevel::DEBUG) << exp->getArgs() << std::endl;
}

//判断交换机是否存在测试
TEST(ExchangeTest,exists_test)
{
    LOG(logLevel::DEBUG) << hosts->exists("exchange-1") << std::endl;
    LOG(logLevel::DEBUG) << hosts->exists("exchange-2") << std::endl;
    LOG(logLevel::DEBUG) << hosts->exists("exchange-3") << std::endl;
}

//获取交换机管理数量测试
TEST(ExchangeTest,getSize_test)
{
    LOG(logLevel::DEBUG) << hosts->size() << std::endl;
}


int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    int ret = RUN_ALL_TESTS();
    return 0;
}